package LEKIEUANH.ARRAYS.EX06;

public class StudentControllers {
	public void StudentSort(StudentEntity[] objStudentEntity){
		for(int i = objStudentEntity.length-1;i>=1;i--){
			//Find the maximum in the list
			StudentEntity currentScore = objStudentEntity[0];
			int currentMaxIndex = 0;
			{
				for(int j = 1;j<=i;j++){
					if(currentScore.getStudentScore()>objStudentEntity[j].getStudentScore()){
						currentScore = objStudentEntity[j];
						currentMaxIndex = j;
					}
				}
				//swap
				if(currentMaxIndex!=0){
					objStudentEntity[currentMaxIndex]=objStudentEntity[i];
					objStudentEntity[i]=currentScore;
				}
			}
		}
	}
	//Bubble Sort
	
	public void SapXepSV(StudentEntity[] objSV){
		for(int i = 0;i<objSV.length-1;i++){
			for(int j = i+1;j<objSV.length;j++){
				if(objSV[i].getStudentScore()>objSV[j].getStudentScore()){
					StudentEntity temp = objSV[i];
					objSV[i] = objSV[j];
					objSV[j]=temp;
				}
			}
		}
	}
	//Insertion Sort
	public static void insertionSort(StudentEntity[] objStudent) {
	      for (int i = 1; i < objStudent.length; i++) {
	        /** insert list[i] into a sorted sublist list[0..i-1] so that
	             list[0..i] is sorted. */
	        StudentEntity currentElement = objStudent[i];
	        int k;
	        for (k = i - 1; k >= 0 && objStudent[k].getStudentScore() > currentElement.getStudentScore(); k--) {
	        	objStudent[k + 1] = objStudent[k];
	       }
	       // Insert the current element into list[k+1]
	        objStudent[k + 1] = currentElement;
	     }
	   }
}
